#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int f[1100], g[1100], ans = 0;
int n;
double a[1100];
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%lf", &a[i]);
	for (int i = 1; i <= n; i++)
	{
		f[i] = 1;
		for (int j = i - 1; j >= 1; j--)
			if (a[j] < a[i]) f[i] = max(f[i], f[j] + 1);
	}
	for (int i = n; i >= 1; i--)
	{
		g[i] = 1;
		for (int j = i + 1; j <= n; j++)
			if (a[i] > a[j]) g[i] = max(g[i], g[j] + 1);
	}
	for (int i = 2; i <= n; i++)
		f[i] = max(f[i], f[i - 1]);
	for (int i = n - 1; i >= 1; i--)
		g[i] = max(g[i], g[i + 1]);
	for (int i = 1; i < n; i++)
		ans = max(ans, f[i] + g[i + 1]);
	printf("%d\n", n - ans);
	return 0;
}
